package com.easy.service.impl;

import com.easy.annotation.LogMethod;
import com.easy.bean.Schedule;
import com.easy.mapper.ScheduleMapper;
import com.easy.service.ScheduleService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ScheduleServiceImpl implements ScheduleService {
    @Autowired
    ScheduleMapper scheduleMapper;

    @Override
    public Object page(Page page, Schedule schedule) {
        int count = scheduleMapper.count(schedule);
        page.setCount(count);
        List<Schedule> list = scheduleMapper.page(schedule, page);
        page.setData(list);
        return page;
    }

    @Override
    public List<Map<String, Object>> allTimeSlot(Schedule schedule) {
        return scheduleMapper.allTimeSlot(schedule);
    }

    @Override
    public int decrement_remaining(Integer id) {
        return scheduleMapper.decrement_remaining(id);
    }

    @Override
    public int increment_remaining(Integer id) {
        return scheduleMapper.increment_remaining(id);
    }

    @Override
    public int update_is_deleted(Integer id, Integer is_deleted) {
        return scheduleMapper.update_is_deleted(id, is_deleted);
    }

    @Override
    @LogMethod(serviceName = "新增排班信息")
    public Schedule add(Schedule schedule) {
        scheduleMapper.add(schedule);
        return scheduleMapper.one(schedule.getId());
    }

    @Override
    @LogMethod(serviceName = "删除排班信息")
    public int del(Integer id) {
        return scheduleMapper.del(id);
    }

    @Override
    @LogMethod(serviceName = "修改排班信息")
    public Schedule edit(Schedule schedule) {
        scheduleMapper.edit(schedule);
        return scheduleMapper.one(schedule.getId());
    }

    @Override
    public List<Schedule> all(Schedule schedule) {
        return scheduleMapper.all(schedule);
    }

    @Override
    public Schedule one(Integer id) {
        return scheduleMapper.one(id);
    }

    @Override
    public Object pageWithDoctor(Page page, Schedule sch) {
        int count = scheduleMapper.countWithDoctor(sch);
        page.setCount(count);
        page.setData(scheduleMapper.pageWithDoctor(sch, page));
        return page;
    }

}